package com.foreknow.elmboot.mapper;

import com.foreknow.elmboot.po.DeliveryAddress;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface DeliveryAddressMapper {
    /**
     * 根据用户编号查询所属送货地址
     * @param userId
     * @return
     */
    @Select("select * from DeliveryAddress where userId = #{userId}")
    public List<DeliveryAddress> listDeliveryAddressByUserIdDao(String userId);

    /**
     * 根据送货地址编号查询送货地址
     * @param daId
     * @return
     */
    @Select("select * from deliveryAddress where daId = #{daId}")
    public DeliveryAddress getDeliveryAddressByIdDao(Integer daId);

    /**
     * 向送货地址表中添加一条记录
     * @param deliveryAddress
     * @return
     */
    @Insert("insert into deliveryAddress(contactName,contactSex,contactTel,address,userId) values(#{contactName},#{contactSex},#{contactTel},#{address},#{userId})")
    public int saveDeliveryAddressDao(DeliveryAddress deliveryAddress);

    /**
     * 根据送货地址编号更新送货地址信息
     * @param deliveryAddress
     * @return

     */
    @Update("update deliveryAddress set contactName=#{contactName},contactSex=#{contactSex},contactTel=#{contactTel},address=#{address},userId=#{userId} where daId=#{daId}")
    public int updateDeliveryAddressDao(DeliveryAddress deliveryAddress);

    /**
     * 根据送货地址编号删除一条记录
     * @param daId
     * @return
     */
    @Delete("delete from deliveryAddress where daId=#{daId}")
    public int removeDeliveryAddressDao(Integer daId);
}
